| Conditions | 1 |
| Paths | 32 |
| Total Lines | 59 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 1 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | /** |
||
| 50 | $(() => { |
||
| 51 | window['mmex'] = window['mmex'] || {}; |
||
| 52 | window['mmex']['momentLocal'] = (date) => { |
||
| 53 | if (!date || _.isEmpty(date)) { |
||
| 54 | return moment(); |
||
| 55 | } |
||
| 56 | |||
| 57 | let m = moment(date); |
||
| 58 | if (m.isValid()) { |
||
| 59 | return m; |
||
| 60 | } |
||
| 61 | m = moment(date, "DD.MM.YYYY"); |
||
| 62 | if (m.isValid()) { |
||
| 63 | return m; |
||
| 64 | } |
||
| 65 | |||
| 66 | throw new Error("No supported date format found for ", date); |
||
| 67 | }; |
||
| 68 | |||
| 69 | $.material.init(); |
||
| 70 | |||
| 71 | autosize($('textarea')); |
||
| 72 | |||
| 73 | $("[autofocus]").focus(); |
||
| 74 | |||
| 75 | $(".common-dateinput").each((index, elm) => { |
||
| 76 | let val = $(elm).val(); |
||
| 77 | let date = mmex.momentLocal(val).toDate(); |
||
| 78 | console.log("set date ", date, " out of ", val); |
||
| 79 | new kendo.ui.DateInput($(elm), { |
||
| 80 | value: val ? date : new Date() |
||
| 81 | }); |
||
| 82 | }); |
||
| 83 | |||
| 84 | $(".common-datepicker").each((index, elm) => { |
||
| 85 | let val = $(elm).val(); |
||
| 86 | let date = mmex.momentLocal(val).toDate(); |
||
| 87 | console.log("set date ", date, " out of ", val); |
||
| 88 | new kendo.ui.DatePicker($(elm), { |
||
| 89 | value: val ? date : new Date() |
||
| 90 | }); |
||
| 91 | }); |
||
| 92 | |||
| 93 | $(".common-dropdown-list").each((index, elm) => { |
||
| 94 | new kendo.ui.DropDownList($(elm), { |
||
| 95 | filter: "startswith", |
||
| 96 | }); |
||
| 97 | }); |
||
| 98 | |||
| 99 | $('textarea, input').keyup(function (e) { |
||
| 100 | if (e.which == 17) isCtrl = false; |
||
| 101 | }).keydown(function (e) { |
||
| 102 | if (e.which == 17) isCtrl = true; |
||
| 103 | if (e.which == 13 && isCtrl === true) { |
||
| 104 | $(this).closest('form').submit(); |
||
| 105 | return false; |
||
| 106 | } |
||
| 107 | }); |
||
| 108 | }); |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.